import {
  ModalForm,
  ProFormText,
  ProFormTextArea,
} from "@ant-design/pro-components";
import { Form, message } from "antd";
import React from "react";
import { saveApiGroup, saveSiteMenu } from "../../../../../api";
import { useParams } from "react-router-dom";

const SaveGroupMenu = ({ refresh, children, payload }: any) => {
  const [form] = Form.useForm();
  const urlParams = useParams();
  return (
    <ModalForm
      initialValues={{
        type: 0,
      }}
      width={400}
      trigger={<span>{children}</span>}
      form={form}
      onOpenChange={(open) => {
        form.resetFields()
        if (open && payload) {
          form.setFieldsValue(payload);
        }
      }}
      onFinish={async (e) => {
        e.projectId = urlParams.projectId;
        await saveSiteMenu(e);
        message.success("保存成功");
        refresh();
        return true;
      }}
    >
      <ProFormText hidden  name="siteId" label="site_id" />
      <ProFormText hidden  name="type" label="type" />
      <ProFormText hidden  name="parentId" label="parentId" />
      <ProFormText hidden  name="id" label="分组ID" />
      <ProFormText name="name" label="分组名称" />
      <ProFormText name="icon" label="图标" />
      <ProFormText name="path" label="路径" />
    </ModalForm>
  );
};
export default SaveGroupMenu;
